home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / umich / zt < prev   
Text File  |  1996-10-25  |  4KB  |  154 lines

  1. #!/bin/sh
  2. # -------------------------------------------------------------
  3. #  Copyright (c) 1991 Regents of the University of Michigan.
  4. #  All rights reserved.
  5. #
  6. #  Redistribution and use is permitted provided that this notice 
  7. #  is preserved and that due credit is given to the University of 
  8. #  Michigan. The name of the University may not be used to endorse 
  9. #  or promote products derived from this software without specific 
  10. #  prior written permission. This software is provided "as is" 
  11. #  without express or implied warranty.
  12. # -------------------------------------------------------------
  13.  
  14. # -------------------------------------------------------------
  15. #  tailor to your system
  16. # -------------------------------------------------------------
  17.  
  18. ##
  19. ##  Where is the zone transfer binary?
  20. ##
  21. XFER=/usr/etc/in.named-xfer 
  22.  
  23. ##
  24. ##  Where are scratch files kept?
  25. ##
  26. TMP=/usr/tmp
  27.  
  28. # -------------------------------------------------------------
  29. #  you should not need to touch anything below this point
  30. # -------------------------------------------------------------
  31. OUT=$TMP/.zt.out.$$
  32. TEMP=$TMP/.zt.$$
  33. ZLIST=$TMP/.zlist.$$
  34.  
  35. # -------------------------------------------------------------
  36. #  Do args
  37. #    -R    Recursive.  Grab all zones below give zone too.
  38. #    -d    Debug.  Print handy debugging info.
  39. # -------------------------------------------------------------
  40. RECURSE=0 
  41. DEBUG=0 
  42.  
  43. if [ $# = 0 ] ; then
  44.     echo "Usage: [-R] [-d] zone"
  45.     exit -1
  46. fi
  47. while [ $# != 1 ] ; do
  48.     case "$1" in
  49.         -R)
  50.         RECURSE=1
  51.         ;;
  52.  
  53.         -d)
  54.         DEBUG=1
  55.         ;;
  56.  
  57.         -?)
  58.         echo Illegal arg $1
  59.         exit -1
  60.         ;;
  61.  
  62.     esac
  63.     shift
  64. done
  65. ZONELIST=$1
  66.  
  67. while [ 1 ] ; do
  68.     #----------------------------------------------------
  69.     # Loop through the list of zones
  70.     #----------------------------------------------------
  71.     DONE=1
  72.     for ZONE in $ZONELIST ; do
  73.         #----------------------------------------------------
  74.         #  Get the addr of the zone's nameservers
  75.         #----------------------------------------------------
  76.         dig $ZONE NS > $TEMP 2> /dev/null
  77.         if [ $? -ne 0 ] ; then
  78.             echo Zone $ZONE unknown or nameserver unavailable
  79.             exit -1
  80.         fi
  81.         NSLIST=`cat $TEMP | awk '$3 == "A" { print $4 }'`
  82.         #----------------------------------------------------
  83.         #  Use named-xfer to bring over a copy of the zone
  84.         #  Use 0 as the serial # since will likely be less
  85.         #  than the current serial number in the SOA
  86.         #----------------------------------------------------
  87.         for I in $NSLIST ; do
  88.             if [ $DEBUG = 1 ] ; then
  89.                 echo Trying nameserver at address $I
  90.             fi
  91.             $XFER -z $ZONE -f $TMP/$ZONE.$$ -s 0 $I
  92.             if [ $? = 1 ] ; then
  93.                 grep -v ";" $TMP/$ZONE.$$ |
  94.                 awk '{
  95.                     if ($1 == "$ORIGIN") {
  96.                         origin=$2
  97.                         if (origin != old) {
  98.                             old = origin
  99.                             print $0
  100.                         }
  101.                     }
  102.                     else
  103.                         print $0
  104.                 }' >> $OUT
  105.                 if [ $DEBUG = 1 ] ; then
  106.                     echo Got zone $ZONE
  107.                 fi
  108.                 break
  109.             elif [ $DEBUG = 1 ] ; then
  110.                 echo Nameserver $I for $ZONE not working
  111.             fi
  112.         done
  113.         rm -f $TEMP
  114.         #----------------------------------------------------
  115.         #  If we're doing a recursive query, capture the NS
  116.         #  records to build a new ZONELIST of subdomains
  117.         #----------------------------------------------------
  118.         SUBZONES=""
  119.          if [ $RECURSE -eq 1 -a -s $TMP/$ZONE.$$ ] ; then
  120.              awk '{
  121.                  if ($1 == "$ORIGIN")
  122.                      origin = substr($2, 1, length($2) - 1)
  123.                  else if ($3 == "NS") {
  124.                      sub = $1 "." origin
  125.                      if (sub != zone)
  126.                          print sub
  127.                  }
  128.              }' zone=$ZONE $TMP/$ZONE.$$ > $ZLIST
  129.              if [ -s $ZLIST ] ; then
  130.                  SUBZONES=`echo $SUBZONES ; sort -u $ZLIST`
  131.                  DONE=0
  132.              fi
  133.              rm -f $ZLIST
  134.          fi
  135.         rm -f $TMP/$ZONE.$$
  136.     done
  137.     #----------------------------------------------------
  138.     #  If we weren't recursive, or we were recursive and
  139.     #  have run out of subdomains, we're done
  140.     #----------------------------------------------------
  141.     if [ $DONE -eq 1 ] ; then
  142.         if [ -s $OUT ] ; then
  143.             cat $OUT
  144.         else
  145.             echo "Could not perform a zone transfer of $1"
  146.         fi
  147.         rm -f $OUT
  148.         exit 0
  149.     else
  150.         ZONELIST=$SUBZONES
  151.     fi
  152. done
  153. exit 0
  154.